package com.sky.blog.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author sky  2022/3/22
 * @version 1.0
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket sky(@Qualifier("apiInfo") ApiInfo apiInfo) {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("rubbish-forward")
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sky.blog.controller"))
                .build();
    }

    @Bean
    public Docket admin(@Qualifier("apiInfo") ApiInfo apiInfo) {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("rubbish-back")
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public ApiInfo apiInfo() {
        Contact contact = new Contact("sky", "blog.sky.com", "1654939047@qq.com");
        return new ApiInfo(
                "垃圾博客",
                "超越传统的垃圾博客",
                "1.0",
                "urn:tos",
                contact,
                "Apache 2.0",
                "https://www.blog.sky.com",
                new ArrayList<>());
    }
}
